package com.hhu.wangzb.server.service.impl;

import com.hhu.wangzb.server.service.LowAcCableService;
import com.hhu.wangzb.server.service.LowDcCableService;
import com.hhu.wangzb.server.service.PvSpeCableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhu.wangzb.common.utils.PageUtils;
import com.hhu.wangzb.common.utils.Query;

import com.hhu.wangzb.server.dao.LowVolLineDao;
import com.hhu.wangzb.common.entity.LowVolLineEntity;
import com.hhu.wangzb.server.service.LowVolLineService;


@Service("lowVolLineService")
public class LowVolLineServiceImpl extends ServiceImpl<LowVolLineDao, LowVolLineEntity> implements LowVolLineService {

    @Autowired
    PvSpeCableService pvSpeCableService;

    @Autowired
    LowDcCableService lowDcCableService;

    @Autowired
    LowAcCableService lowAcCableService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<LowVolLineEntity> page = this.page(
                new Query<LowVolLineEntity>().getPage(params),
                new QueryWrapper<LowVolLineEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        // 查询自身
        List<LowVolLineEntity> lowVolLineEntities = baseMapper.selectBatchIds(idList);

        // 删除子节点
        for (LowVolLineEntity entity : lowVolLineEntities) {
            if (entity.getPscId() != null) pvSpeCableService.removeById(entity.getPscId());
            if (entity.getLacId() != null) lowAcCableService.removeById(entity.getLacId());
            if (entity.getLdcId() != null) lowDcCableService.removeById(entity.getLdcId());
        }

        // 删除自身
        return super.removeByIds(idList);
    }
}